package jml.defaultimple.util;

import java.io.File;
import java.util.Stack;

public class FolderIterator
{
	private File root=null;
	private Stack<File> stack;
	
	public FolderIterator(File f)
	{
		this.root=f;
		this.stack=new Stack<File>();		
		stack.push(f);
	}
	
	public boolean hasNext()
	{
		return !stack.isEmpty();
	}
	
	public File next()
	{
		File x = stack.pop();
		
		// recoro todos los folders
		String lst[] = x.list();
		for(int i = 0; lst!=null && i < lst.length; i++)
		{
			File f1 = new File(x.getAbsolutePath() + "/" + lst[i]);
			if(f1.isDirectory())
			{
				stack.push(f1);
			}
		}

		return x;
	}
}
